// index.js
// 获取应用实例
const app = getApp()
import config from '~/configs/configs'
import baseuser from '~/utils/users.js'
Page({
  data: {
    statusBarHeight: 0,
    height: 46,
    bannerlist: [],
    swiperitem: 0,

    option1: [],
    optionvalue1: 0,
    optionvalue2: 0,
    isShowPopup1: false,

    isShowPopup2: false,
    option2: [
      // {
      //   text: '全部',
      //   value: 0
      // },
      // {
      //   text: '10-100',
      //   value: 1
      // },
    ],
    optionvalue2: 0,

    indexlist: [],
    tlist: {
      classify: '家用电器',
      minPrice: 0,
      maxPrice: 100,
      latestRelease: 1,
      current: 1,
      pageSize: 10,
    },
    pages: 1,
    linme: 10,

    value: '',
    synthesis: 1,
    upToDate: 0,
    latestRelease: 1
  },
 dropchange2(items) {
   console.log(items);
    this.setData({
      optionvalue2: items.detail
    })
    let detail = items.detail; // 获取detail属性    
    let parts = detail.split('-'); // 使用 '-' 分割字符串    
    let min = parseInt(parts[0]); // 解析第一部分（20）为整数    
    let max = parseInt(parts[1]); // 解析第二部分（50）为整数   
    console.log(min); // 输出：20    
    console.log(max); // 输出：50
    this.tlist = {
      classify: '',
      minPrice: min,
      maxPrice: max,
      latestRelease: 1,
      current: 1,
      pageSize: 10,
      
    }
    this.getcommlist(this.tlist)
  },
  // 获取价格列表
  async getpriceList() {
    let reqdata = await baseuser.priceList()
    let newdata1 = reqdata.data.Result
    for (const i in newdata1) {
      newdata1[i].text = newdata1[i].minPrice +'-'+ newdata1[i].maxPrice
      newdata1[i].value = newdata1[i].minPrice +'-'+newdata1[i].maxPrice

  }

    this.setData({
    option2: newdata1
  })
  console.log('option2', newdata1); 
},

// 点击综合
async onclikzong() {
    if (this.data.synthesis == 0) {
      this.setData({
        synthesis: 1,
        upToDate: 0
      })
      this.getcommlist()
    } else {
      this.setData({
        synthesis: 0
      })
    }
  },
  async newDate(items) {
      console.log('items', items);
      if (this.data.upToDate == 0) {
        this.setData({
          synthesis: 0,
          upToDate: 1
        })
        this.tlist = {
          classify: '',
          minPrice: 10,
          maxPrice: 100,
          latestRelease: 1,
          current: 1,
          pageSize: 10,
        }
        this.getcommlist(this.tlist)

      } else {
        this.setData({
          newDate: 0
        })
      }
    },
    async gatbanner() {
        let reqdata = await baseuser.indexbanner()
        let bannerlist = reqdata.data.result
        this.setData({
          bannerlist
        })
      },
      async getfenlei() {
          let resdata = await baseuser.profirst()
          // console.log('rress',resdata);
          let newdata = resdata.data.result
          for (const i in newdata) {
            newdata[i].text = newdata[i].name
            newdata[i].value = newdata[i].name
          }
          this.setData({
            option1: newdata
          })
          console.log('newdata', this.data.option1);

        },
        nextcalendar() {
          wx.navigateTo({
            url: `../calendar/calendar`,
          })
        },
        nextselection() {
          wx.navigateTo({
            url: `../selection/selection`,
          })
        },
        nextexplosives() {
          wx.navigateTo({
            url: `../explosives/explosives`,
          })
        },
        nextdetail(e) {
          console.log('e', e.currentTarget.dataset.id);
          wx.navigateTo({
            url: `../details/details?id=${e.currentTarget.dataset.id}`,
          })
        },
        gotoSquare_supplier_search() {
          wx.navigateTo({
            url: `/pages/square_supplier_search copy/supplier_search`,
          })
        },
        open_dropdown() {
          wx.setPageStyle({
            style: {
              overflow: 'hidden'
            }
          })
          this.setData({
            isShowPopup1: true
          })
        },
        close_dropdown() {
          wx.setPageStyle({
            style: {
              overflow: ''
            }
          })
          this.setData({
            isShowPopup1: false
          })
        },

        swiperchange(e) {
          this.setData({
            swiperitem: e.detail.current
          })
        },
        dropchange1(items) {
          this.setData({
            optionvalue1: items.detail,
            
          })
          // console.log('item11111',items);
          this.tlist = {
            classify: items.detail,
            minPrice: 10,
            maxPrice: 100,
            latestRelease: 1,
            current: 1,
            pageSize: 10,
          }
          this.getcommlist(this.tlist)
        },
        onLoad() {
          let statusBarHeight = (0, wx.getSystemInfoSync)().statusBarHeight;
          this.setData({
            statusBarHeight: statusBarHeight,
            height: 46 + statusBarHeight,
          });
          this.getfenlei()
          this.gatbanner()
          this.getcommlist(this.tlist)
          // this.getScreen()
          this.getpriceList()
        },

        async getcommlist(tlist) {
            // console.log("tlist",tlist)
            let reqdata = await baseuser.indexcommlist(tlist)
            this.setData({
              indexlist: reqdata.data.Result.records
            })
          },
          async getScreen(detail) {
              let setdata = {
                classify: detail,
                minPrice: 100,
                maxPrice: 300,
                latestRelease: 1,
                current: 1,
                pageSize: 10
              }
              let reqdata = await baseuser.getScreen(setdata)
              // console.log('66666666', reqdata)
              this.setData({
                indexlist: reqdata.data.result.records

              })
            },

})